/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package ca.usherbrooke.mainApp.view.agent;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTable;

import ca.usherbrooke.agent.controller.shared.IAgent;
import ca.usherbrooke.goal.BasicGoal;
import ca.usherbrooke.goal.EntityGoal;
import ca.usherbrooke.mainApp.view.utils.MyTableModel;

/**
 * @author Cody Stoutenburg
 * 
 */
public class PanelListGoalSolved<E extends IAgent> extends JPanel {
	private static final long serialVersionUID = 1L;

	protected final E agentGetter;

	protected final JTable tableList;
	protected final MyTableModel tableModel;

	public PanelListGoalSolved(E agent) {
		super();

		this.agentGetter = agent;
		tableModel = new MyTableModel();

		tableList = new JTable(tableModel);
		tableList.setPreferredSize(new Dimension(500, 100));
		tableList.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

		tableModel.addColumn(String.class, "Description");
		tableModel.addColumn(String.class, "Score Total");
		tableModel.addColumn(String.class, "Score Fail");
		tableModel.addColumn(String.class, "Score Received");
		tableModel.addColumn(String.class, "Remaining time");
		tableModel.addColumn(String.class, "does fail");

		this.add(tableList);
		reloadData();
	}

	public void reloadData() {
		tableModel.clear();
		EntityGoal goals = agentGetter.getGoals();
		for (BasicGoal goal : goals.getAllGoalsSolved()) {
			List<Object> values = new ArrayList<Object>();
			values.add(goal.getDescription());
			values.add(goal.getScoreTotal());
			values.add(goal.getScoreFail());
			values.add(goal.getCurrentScore());
			values.add(goal.getRemainingTime());
			values.add(goal.isFail());
			tableModel.addRow(values);
		}
		tableList.doLayout();
		this.revalidate();
	}
}
